package edu.nf.meituan.dao.rider.impl;

import edu.nf.meituan.dao.rider.RiderDAO;
import edu.nf.meituan.model.rider.Rider;
import edu.nf.util.DBUtils;
import org.nf.db.util.SqlExecutor;
import org.nf.db.util.result.BeanHandler;

/**
 * @Date 2023-06-20
 * @Author qiu
 * 骑手接口实现类
 */
public class RiderDAOImpl implements RiderDAO {
    /**
     * 骑手登录
     * @param riderName 骑手姓名
     * @return
     */
    @Override
    public Rider loginRider(String riderName) {

        SqlExecutor sqlExecutor = new SqlExecutor(DBUtils.getConnection());

        String sql = "select rider_name,rider_phone,rider_type from rider where rider_name = ?";

        BeanHandler<Rider> riderBeanHandler = new BeanHandler<>(Rider.class);

        return sqlExecutor.executeQuery(sql,riderBeanHandler,riderName);
    }

    /**
     * 骑手注册
     * @param riderName
     * @param riderPhone
     * @param riderType
     * @return
     */
    @Override
    public int registerRider(String riderName, String riderPhone, String riderType) {
        SqlExecutor sqlExecutor = new SqlExecutor(DBUtils.getConnection());

        String sql = "insert into rider(rider_name,rider_phone,rider_type) values(?,?,?)";

        return sqlExecutor.executeUpdate(sql,riderName,riderPhone,riderType);
    }

    @Override
    public Rider equeryRider(String riderPhone) {

        SqlExecutor sqlExecutor = new SqlExecutor(DBUtils.getConnection());
        String sql = "select rider_phone from rider where rider_phone = ?";

        BeanHandler<Rider> riderBeanHandler = new BeanHandler<>(Rider.class);

        return sqlExecutor.executeQuery(sql,riderBeanHandler,riderPhone);
    }
}
